Blog

Jon Clausen

February 16, 2024

Spread the word


Share your thoughts

v3.3.0 released!

 

We are very excited to bring you another release for our Redis Lucee Extension. The most significant feature in this release is the addition of the <cfRedisLock>/redisLock{} tag, which allows you perform a lock across all instances in a cluster.

When running in a clustered environment, it is often desirable that a specific action or assignment be performed by one user. Take, for example, the following code:

var customer = customerService.get( customerId );
var hotelRoom = hotelService.getRoom( roomNumber );
reservationService.reserve( hotelRoom, customer );

In a clustered environment, we would want to prevent the same same hotel room from potentially being reserved by two separate guests ( because: awkward....! )

With the redisLock tag, we now have the ability to prevent concurrent attempts to perform the same action by two users in the system. The method signature for both redisLock and cfRedisLock is as follows:

redisLock
    name="[ the name of the lock to place ]"
    cache="[ the configured redis cache to use for locking ]"
    throwOnTimeout="[ Defaults to true, whether to throw on failure to lock]"
    expires="[the max duration of the lock entry to exists in seconds - default 60s]"
    timeout="[the max time to wait for a lock to be acquired - default 2s]"
    bypass="[optional - if true will bypass the attempt to lock completely]"
{
.... do locked stuff here ...
}

Using our hotel reservation example, we can now perform a distributed lock like so:

var customer = customerService.get( customerId );
var hotelRoom = hotelService.getRoom( roomNumber );
redisLock
    name="reservationSystem_ReserveRoom_#roomNumber#"
    cache="redis-data"
    throwOnTimeout=false
    bypass=isDevelopmentMode() || isTestMode()
  {
     reservationService.reserve( hotelRoom customer );
	 return "Room number #roomNumber# has been successfully reserved!";
  }
  return "Room number #roomNumber# has already been reserved. Please select another room";

In this example, we set the throwOnTimeout value to false. If we fail to achieve a lock, it means the same room was being reserved and the code inside the body of the lock is not executed. As such, we return that the room was not able to be reserved. Note the use of the bypass argument to the lock. This can be handy for development or in testing when you are not using a distributed cache ( though you will need to have the extension installed to recognize what redisLock is! ) and simply want to execute the block.

Ortus Redis Extension v3.3.0 gives you greater control over concurrent modifications in a distributed environment, utilizing your distributed cache to prevent overlaps!

Read the full documentation here: Ortus Redis Cache Extension Documentation

 

Purchase Extension


Resources

Please visit our Extension page for all the necessary resources.

Add Your Comment

Recent Entries

The Hidden Costs of In-House Database Management

The Hidden Costs of In-House Database Management

The Hidden Costs of In-House Database Management


Opting for in-house database management involves more than just a salary. Here are some often-overlooked costs associated with maintaining your own DBA team.



1. High Salaries and Benefits


Hiring skilled DBAs is expensive. According to industry reports, the average salary of a DBA in the U.S. can range from $85,000 to over $130,000 per year, depending on experience and expertise. When you add ...

Cristobal Escobar
Cristobal Escobar
November 20, 2024
5 Signs It’s Time to Modernize Your ColdFusion / CFML Application

5 Signs It’s Time to Modernize Your ColdFusion / CFML Application

ColdFusion has long been a reliable platform for building web applications, but like any technology, it requires maintenance and modernization over time. Whether you're using Lucee or Adobe ColdFusion, it’s critical to recognize the signs that your application is no longer meeting today’s standards in performance, security, and scalability. Let’s explore five clear indicators that it’s time to modernize your ColdFusion application and how ColdFusion consulting can help breathe new life into y...

Cristobal Escobar
Cristobal Escobar
November 19, 2024
ColdBox Free Tip 5 - Building Named Routes with a Struct

ColdBox Free Tip 5 - Building Named Routes with a Struct

**Did you know ColdBox provides flexible ways to build routes using structs?** In this tip, we’ll cover how to use the `event.buildLink()` and `event.route()` methods for named routes, a feature that’s especially handy when working with dynamic URLs.

Maria Jose Herrera
Maria Jose Herrera
November 19, 2024